package com.skytech.tax.customsdatawarehouse.singlewindow.customsdeclarations.domain.dao;

import com.skytech.tax.customsdatawarehouse.singlewindow.customsdeclarations.domain.entity.IECustomsDeclarationRet;
import org.joda.time.DateTime;
import org.springframework.jdbc.core.namedparam.BeanPropertySqlParameterSource;
import org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate;
import org.springframework.stereotype.Repository;

import javax.annotation.Resource;

/**
 * @author Lianhong
 * @since 2022/6/30
 */
@Repository("singleWindow.ieCustomsDeclarationRetDao")
public class IECustomsDeclarationRetDao {

    @Resource
    private NamedParameterJdbcTemplate namedParameterJdbcTemplate;

    private String saveCustomsDeclarationRetSql = "INSERT INTO gd_jckhwgd_ret (cusCiqNo, ret, storageTime) VALUES (:cusCiqNo, :ret, :storageTime)";

    public void save(IECustomsDeclarationRet ret) {
        ret.setStorageTime(DateTime.now().toString("yyyy-MM-dd HH:mm:ss"));
        this.namedParameterJdbcTemplate.update(this.saveCustomsDeclarationRetSql, new BeanPropertySqlParameterSource(ret));
    }

    private String deleteCustomsDeclarationRetSql = "DELETE FROM gd_jckhwgd_ret WHERE cusCiqNo = ?";

    public void delete(String cusCiqNo) {
        this.namedParameterJdbcTemplate.getJdbcOperations().update(this.deleteCustomsDeclarationRetSql, cusCiqNo);
    }

}
